package com.sun.baizhi.workqueue;

import com.rabbitmq.client.*;
import com.sun.baizhi.utils.RabbitMQUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class Consumer {
    public static void main(String[] args) {
        String host = "123.56.180.207";
        Integer port = 5672;
        String virtualHost = "/ems";
        String userName = "ems";
        String passWord = "123";
        Connection connection = null;
        Channel channel = null;
        try{
            connection = RabbitMQUtil.getConnection(host, port, virtualHost, userName, passWord);
            channel = connection.createChannel();
            channel.queueDeclare("work",true,false,false,null);
            channel.basicConsume("work",true,new DefaultConsumer(channel){
                @Override
                public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                    System.out.println("消费者=========1得到的消息" + new String(body, StandardCharsets.UTF_8));
                }
            });
        }catch (Exception e){

        }finally {
//            RabbitMQUtil.close(connection,channel);
        }
    }
}
